package com.gress.shop.service.impl;

import com.gress.shop.bo.LogInfo;
import com.gress.shop.bo.example.LogInfoExample;
import com.gress.shop.dao.ILogInfoDao;
import com.gress.shop.service.IAccessLogService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created xiongwen with 2018/3/8 19:48
 * Description:
 */
@Service
public class AccessLogService implements IAccessLogService{


    @Resource
    private ILogInfoDao logInfoDao;

    @Override
    public void saveLog(LogInfo info) {
        logInfoDao.insertLogInfo(info);
    }

    @Override
    public List<LogInfo> queryLogInfo(LogInfoExample example) {
        example.createCriteria().andIsValidEqualTo(1);
        return logInfoDao.queryListLogInfo(example);
    }

    @Override
    public List<LogInfo> queryByRegion(long startTime, long endTime, String email) {
        LogInfoExample example = new LogInfoExample();
        if (StringUtils.isEmpty(email)) {
            example.createCriteria()
                    .andCreateTimeBetween(startTime, endTime)
                    .andIsValidEqualTo(1);
        }else {
            example.createCriteria()
                    .andCreateTimeBetween(startTime, endTime)
                    .andIsValidEqualTo(1)
                    .andCreateByEqualTo(email);
        }
        return logInfoDao.queryListLogInfo(example);
    }
}
